//
//  KMUserInfoManager.m
//  UserInfoManager
//
//  Created by 陈家将 on 16/6/1.
//  Copyright © 2016年 szteyou. All rights reserved.
//

#define kUserInfoKey @"KMUSERKEY"

#import "KMUserInfoManager.h"
#import "MJExtension.h"

@implementation KMUserInfoManager

+ (BOOL)isLogin {
    KMUserInfo *uDefault = [KMUserInfoManager getInfo];
    @synchronized(uDefault) {
        if (!uDefault) {
            return NO;
        }
    return uDefault.customer_id.length ? YES : NO;
    }
}

+ (void)saveInfo:(KMUserInfo *)info {
    NSMutableDictionary *infoDic = [info mj_keyValues];
    NSUserDefaults *uDefault = [NSUserDefaults standardUserDefaults];
    @synchronized(uDefault) {
    [uDefault setObject:infoDic forKey:kUserInfoKey];
    [uDefault synchronize];
    }
}

+ (KMUserInfo *)getInfo {
    NSUserDefaults *uDefault = [NSUserDefaults standardUserDefaults];
    @synchronized(uDefault) {
        NSMutableDictionary *infoDic = [uDefault objectForKey:kUserInfoKey];
        if (!infoDic) {
            return nil;
        }
        KMUserInfo *km_userInfo = [KMUserInfo mj_objectWithKeyValues:infoDic];
        return km_userInfo;
    }
}

+ (void)deleteInfo {
    NSUserDefaults *uDefault = [NSUserDefaults standardUserDefaults];
    @synchronized(uDefault) {
    [uDefault removeObjectForKey:kUserInfoKey];
    }
}

@end
